package com.ztc.ZtcRefundRatio.dao;
import com.ztc.ZtcRefundRatio.bean.ZtcRefundRatio;
import java.util.List;
import org.springframework.stereotype.Repository; 
import com.aqgj.util.BaseDaoImpl;

@Repository("ZtcRefundRatioDao")
public class ZtcRefundRatioDao extends BaseDaoImpl<ZtcRefundRatio> {

    public String save(ZtcRefundRatio ztcRefundRatio){
        this.getHibernateTemplate().save(ztcRefundRatio);
        return ztcRefundRatio.getId();
    }
    public ZtcRefundRatio getRefundRatioRefundTimeByTransportId(String transportId){
        String sql = "select a.* from ztc_transport t\n" +
                "    inner join ztc_refund_ratio_info i on i.create_transport_id = t.id\n" +
                "    inner join ztc_refund_ratio a on a.ztc_refund_ratio_info_id = i.id\n" +
                "    where" +
                "    i.create_transport_id = ? and a.is_refund = 2\n";
        List<ZtcRefundRatio> refundRatioList = this.currentSession().createNativeQuery(sql,ZtcRefundRatio.class).setParameter(1,transportId).getResultList();
        if(refundRatioList == null || refundRatioList.size() == 0){
            return null;
        }
        return refundRatioList.get(0);
    }
    public List<ZtcRefundRatio> getRefundRatioTransportId(String transportId){
        String sql = "select a.* from ztc_transport t\n" +
                "    inner join ztc_refund_ratio_info i on i.create_transport_id = t.id\n" +
                "    inner join ztc_refund_ratio a on a.ztc_refund_ratio_info_id = i.id\n" +
                "    where\n" +
                "    i.create_transport_id = ? and a.is_refund = 1";
        return this.currentSession().createNativeQuery(sql,ZtcRefundRatio.class).setParameter(1,transportId).getResultList();
    }
}